/**
  *****************基于CW32L083的超低功耗天气时钟****************
  * @author  爱电子的梦兮
  * @brief   超低功耗天气时钟
  * @hardware
	*						e-Paper: PA12--SDA  PA11--SCL  PA10--CS  PA09--D/C
	*										 PA08--RES  PC09--BUSY  PF07--POWER (PMOS)
  *						SHT30: PB13--SDA  PB12--SCL
	*						ADC0(采集电池电压): PA00
	*						KEY(上/左/确定)：PF4 KEY(下/右/退出)：PA3
	*						陶瓷压电片：PA5  (NMOS)
	*						ESP12F：串口2(AF4):PB03(TXD) PB04(RXD) POWER--PB14 (PMOS)
  ****************************************************************
  */

#include "main.h"

u8	Image_BW[4000]={0}; //E_Paper缓冲区
u8	wakeup_flag=0; //RTC中断任务标志
u16 OneDay_Flag=0; //每天获取一次天气预报
u8 HalfHour_Flag=0; //半小时校准一次当前天气

//天气数据
char code[10]="00"; //当前天气
float temp;
char ip[20]="Taiyuan";
struct Daily_Fcsts{	//天气预报
  char code_day[10]; //白天天气
  char code_night[10];
  int8_t high; //最高温度
  int8_t low;
} today={"00","00",0,0},tomorrow={"00","00",0,0},acquired={"00","00",0,0};

struct tm{//网络时间校准
  u8	sec;
  u8	min;
  u8	hour;
  u8	day;
  u8	mon;
  u16	year;
	u8  week;
} time;
u8 hour;
u8 UART2_RX_BUF[128];//接收缓冲区
u8 RX_Over=0; //接收一包数据完成标志
u16 UART2_RX_LEN=0; //包数据长度

//extern struct KEYdataBase KeyData;
void Show_Data(void);
void Time_Init(void);
void Update_CurrentWeather(void);
void Update_ForeWeather(void);
void NVIC_Configuration(void);

void AdcInit()
{
	ADC_InitTypeDef ADC_InitStructure = {0};
	ADC_SingleChTypeDef ADC_SingleChStructure = {0};
	//ADC默认值初始化
	REGBITS_SET(CW_SYSCTRL->APBEN2, SYSCTRL_APBEN2_ADC_Msk);//打开ADC时钟
  ADC_StructInit(&ADC_InitStructure);
	//IO初始化
  REGBITS_SET(CW_SYSCTRL->AHBEN, SYSCTRL_AHBEN_GPIOA_Msk);//打开GPIO时钟
	PA00_ANALOG_ENABLE();//set PA00 as AIN0 INPUT

	//配置单通道转换模式
  ADC_SingleChStructure.ADC_DiscardEn = ADC_DiscardNull;
  ADC_SingleChStructure.ADC_Chmux = ADC_ExInputCH0; //选择ADC转换通道，AIN0:PA00
  ADC_SingleChStructure.ADC_InitStruct = ADC_InitStructure;
	ADC_SingleChOneModeCfg(&ADC_SingleChStructure);
}

int32_t main(void)
{
		RCC_HSI_Enable( RCC_HSIOSC_DIV6 ); //8Mhz
		RCC_LSE_Enable(RCC_LSE_MODE_OSC, RCC_LSE_AMP_NORMAL, RCC_LSE_DRIVER_NORMAL);	//LSE打开
		NVIC_Configuration();	//中断优先级设置
		delay_Init();	//延时
		Power_Init();	//电源引脚
		SHT30_Init(); //温湿度
		//KEY_Init();
		Uart2_Init();
		AdcInit();
    RCC_WAKEUPCLK_Config(RCC_SYSCTRL_WAKEUPCLKDIS);	//深度休眠唤醒后时钟源：系统时钟
		Update_CurrentWeather();
		Update_ForeWeather();
		Time_Init();	//上电复位才能WIFI校准时间，请在1分钟内连接WiFi：CW32 LPow Clock
		Show_Data();	//更新数据
    while(1)
    {
			 if(wakeup_flag)
			 {
				  wakeup_flag=0;
					OneDay_Flag++;
					HalfHour_Flag++;
					if(OneDay_Flag>1440)
					{
						OneDay_Flag=0;
						Update_ForeWeather();
					}
					if(HalfHour_Flag>30)
					{
						HalfHour_Flag=0;
						Update_CurrentWeather();
					}
				  Show_Data();	//更新数据
					SCB->SCR = SCB_SCR_SLEEPDEEP_Msk;	//设置SLEEP_DEEP=1
					__WFI(); //立即进入深度睡眠
			 }
		}
}

void RTC_IRQHandlerCallBack(void)	//RTC中断自动唤醒
{
    if (RTC_GetITState(RTC_IT_INTERVAL))
    {
			wakeup_flag=1;
			RTC_ClearITPendingBit(RTC_IT_INTERVAL);
    }
}

void UART2_UART5_IRQHandlerCallBack(void) //串口2中断自动唤醒
{
	u8 res;
	if(UART_GetITStatus(CW_UART2, UART_IT_RC) != RESET)
  {
		UART_ClearITPendingBit(CW_UART2, UART_IT_RC);	//清中断标志位
		res = UART_ReceiveData_8bit(CW_UART2); //读取数据
		if(RX_Over==0) {
			UART2_RX_BUF[UART2_RX_LEN]=res;
			if( UART2_RX_BUF[0] =='{') UART2_RX_LEN++;	//继续接收
			if(res =='}') RX_Over=1;
		}
  }
}

void Time_Init() //WIFI校准时间
{		
		u8 error=0;
		if ((RCC_GetAllRstFlag() & SYSCTRL_RESETFLAG_POR_Msk) == RCC_FLAG_PORRST)  //不是上电复位不运行
		{
			ESP_Power_ON(); //打开ESP-12F模块电源
			u8 count=0;
			while(count<60){//等待1分钟WiFi稳定后获取时间，请在1分钟内连接好WiFi。
				delay_ms(1000);
				count++;
			}
			printf("5");	//发送获取网络时间指令
			count=0;
			while(RX_Over!=1){ //等待回传cJSON数据包
					delay_ms(100);
					count++;
					if(count>200){	//20S过去，超时处理
						error=1;
						break;
					}
			}
			ESP_Power_OFF();//关电源
			if(error==0){ //有消息才解析
				cJSON* root=cJSON_Parse((const char*)UART2_RX_BUF);	//将JSON字符串转换成JSON结构体
				time.sec=cJSON_GetObjectItem(root,"s")->valueint; //若出现卡死现象，堆区改大点
				time.min=cJSON_GetObjectItem(root,"m")->valueint;
				time.hour=cJSON_GetObjectItem(root,"h")->valueint;
				time.day=cJSON_GetObjectItem(root,"d")->valueint;
				time.mon=cJSON_GetObjectItem(root,"mo")->valueint;
				time.year=cJSON_GetObjectItem(root,"y")->valueint;
				time.week=cJSON_GetObjectItem(root,"w")->valueint;
				cJSON_Delete(root); //cJSON占用大量堆区动态内存，用完连根删除
			}
			memset(UART2_RX_BUF, 0, sizeof(UART2_RX_BUF));
			UART2_RX_LEN=0;
			RX_Over=0;
		}
		RTC_InitTypeDef RTC_InitStruct = {0};
		RCC_APBPeriphClk_Enable1(RCC_APB1_PERIPH_RTC, ENABLE);
		//设置日期，DAY、MONTH、YEAR必须为BCD方式，星期为0~6，代表星期日，星期一至星期六
		u8 year= time.year%100;
    RTC_InitStruct.DateStruct.Year = (year/10)*16+year%10;
		RTC_InitStruct.DateStruct.Month = (time.mon/10)*16+time.mon%10;
		RTC_InitStruct.DateStruct.Week = time.week;
		RTC_InitStruct.DateStruct.Day = (time.day/10)*16+time.day%10;
		RTC_InitStruct.TimeStruct.Hour = (time.hour/10)*16+time.hour%10;   //设置时间，HOUR、MINIUTE、SECOND必须为BCD方式，用户须保证HOUR、AMPM、H24之间的关联正确性
    RTC_InitStruct.TimeStruct.Minute = (time.min/10)*16+time.min%10;
    RTC_InitStruct.TimeStruct.Second = (time.sec/10)*16+time.sec%10;
    RTC_InitStruct.TimeStruct.AMPM = 0;
    RTC_InitStruct.TimeStruct.H24 = 1;
    RTC_InitStruct.RTC_ClockSource = RTC_RTCCLK_FROM_LSE;
    RTC_Init(&RTC_InitStruct);  //用户需选定需要使用的时钟源
		
		RTC_SetInterval(RTC_INTERVAL_EVERY_1M);	 //1分钟中断
		RTC_ITConfig(RTC_IT_INTERVAL, ENABLE);	 //中断使能
}

void Update_CurrentWeather(){ //更新当前预报
		ESP_Power_ON(); //打开ESP-12F模块电源
		u8 count=0;
		u8 error=0;
		while(count<20){//等待20S WiFi稳定后获取时间。
			delay_ms(1000);
			count++;
		}
		printf("6");
		count=0;
		while(RX_Over!=1){ //等待回传cJSON数据包
				delay_ms(100);
				count++;
				if(count>200){	//20S过去，超时处理
					error=1;	
					break;
				}
		}
		ESP_Power_OFF();//关电源
		if(error==0){
			cJSON* root=cJSON_Parse((const char*)UART2_RX_BUF);	//将JSON字符串转换成JSON结构体
			memset(code, 0, sizeof(code));
			memset(ip, 0, sizeof(ip));
			strcpy(code,cJSON_GetObjectItem(root,"c")->valuestring); //若出现卡死现象，堆区改大点
			temp=cJSON_GetObjectItem(root,"t")->valuedouble;
			strcpy(ip,cJSON_GetObjectItem(root,"ip")->valuestring);
			cJSON_Delete(root); //cJSON占用大量堆区动态内存，用完连根删除
		}
		memset(UART2_RX_BUF, 0, sizeof(UART2_RX_BUF));
		UART2_RX_LEN=0;
		RX_Over=0;
}

void Update_ForeWeather(){ //更新天气预报
		ESP_Power_ON(); //打开ESP-12F模块电源
		u8 count=0;
		u8 error=0;
		while(count<20){//等待20S WiFi稳定后获取时间。
			delay_ms(1000);
			count++;
		}
		
		printf("7");//today
		count=0;
		while(RX_Over!=1){ //等待回传cJSON数据包
				delay_ms(100);
				count++;
				if(count>200){	//20S过去，超时处理
					error=1;	
					break;
				}
		}
		if(error==0){
			cJSON* root=cJSON_Parse((const char*)UART2_RX_BUF);	//将JSON字符串转换成JSON结构体
			memset(today.code_day, 0, sizeof(today.code_day));
			memset(today.code_night, 0, sizeof(today.code_night));
			strcpy(today.code_day,cJSON_GetObjectItem(root,"d")->valuestring); //若出现卡死现象，堆区改大点
			strcpy(today.code_night,cJSON_GetObjectItem(root,"n")->valuestring);
			today.high=cJSON_GetObjectItem(root,"h")->valueint;
			today.low=cJSON_GetObjectItem(root,"l")->valueint;
			cJSON_Delete(root); //cJSON占用大量堆区动态内存，用完连根删除
		}
		memset(UART2_RX_BUF, 0, sizeof(UART2_RX_BUF));
		UART2_RX_LEN=0;
		RX_Over=0;
		error=0;
		
		printf("8");//Tomorrow
		count=0;
		while(RX_Over!=1){ //等待回传cJSON数据包
				delay_ms(100);
				count++;
				if(count>200){	//20S过去，超时处理
					error=1;	
					break;
				}
		}
		if(error==0){
			cJSON* Root=cJSON_Parse((const char*)UART2_RX_BUF);	//将JSON字符串转换成JSON结构体
			memset(tomorrow.code_day, 0, sizeof(tomorrow.code_day));
			memset(tomorrow.code_night, 0, sizeof(tomorrow.code_night));
			strcpy(tomorrow.code_day,cJSON_GetObjectItem(Root,"d")->valuestring); //若出现卡死现象，堆区改大点
			strcpy(tomorrow.code_night,cJSON_GetObjectItem(Root,"n")->valuestring);
			tomorrow.high=cJSON_GetObjectItem(Root,"h")->valueint;
			tomorrow.low=cJSON_GetObjectItem(Root,"l")->valueint;
			cJSON_Delete(Root); //cJSON占用大量堆区动态内存，用完连根删除
		}
		memset(UART2_RX_BUF, 0, sizeof(UART2_RX_BUF));
		UART2_RX_LEN=0;
		RX_Over=0;
		error=0;
		
		printf("9");//Acquired
		count=0;
		while(RX_Over!=1){ //等待回传cJSON数据包
				delay_ms(100);
				count++;
				if(count>200){	//20S过去，超时处理
					error=1;	
					break;
				}
		}
		ESP_Power_OFF();//关电源
		if(error==0){
			cJSON* ROOT=cJSON_Parse((const char*)UART2_RX_BUF);	//将JSON字符串转换成JSON结构体
			memset(acquired.code_day, 0, sizeof(acquired.code_day));
			memset(acquired.code_night, 0, sizeof(acquired.code_night));
			strcpy(acquired.code_day,cJSON_GetObjectItem(ROOT,"d")->valuestring); //若出现卡死现象，堆区改大点
			strcpy(acquired.code_night,cJSON_GetObjectItem(ROOT,"n")->valuestring);
			acquired.high=cJSON_GetObjectItem(ROOT,"h")->valueint;
			acquired.low=cJSON_GetObjectItem(ROOT,"l")->valueint;
			cJSON_Delete(ROOT); //cJSON占用大量堆区动态内存，用完连根删除
		}
		memset(UART2_RX_BUF, 0, sizeof(UART2_RX_BUF));
		UART2_RX_LEN=0;
		RX_Over=0;
}

void Update_TH()	//更新室内温湿度
{
	SHT30_read_result(0x44);
	
	//室内温度应该很难到零下，没位置放'-'标识了
	OLED_ShowNum(152,27,Temperature,2,24,BLACK); //温度 整数部分
	OLED_ShowNum(179,27,(int)(Temperature*10)%10,1,24,BLACK); //温度 小数部分
	OLED_DrawRectangle(178,46,180,48,BLACK,1);	//小数点
	OLED_ShowChar(191,27,'C',24,BLACK);		//C
	OLED_DrawCircle(195,30,2,BLACK,0);		//°
	
	OLED_ShowNum(152,67,Humidity,2,24,BLACK); //湿度
	OLED_ShowNum(179,67,(int)(Humidity*10)%10,1,24,BLACK); //湿度 小数部分
	OLED_DrawRectangle(178,86,180,88,BLACK,1);	//小数点
	OLED_ShowChar(191,67,'%',24,BLACK);		//C
}

void Update_Time() //刷新显示时间
{
		RTC_TimeTypeDef RTC_TimeStruct = {0};
		RTC_DateTypeDef RTC_DateStruct = {0};

		RTC_GetDate(&RTC_DateStruct);
		RTC_GetTime(&RTC_TimeStruct);
		OLED_ShowNum(5,0,20,2,16,BLACK);	//20
		OLED_ShowNum(21,0,(RTC_DateStruct.Year & 0x0f)+(RTC_DateStruct.Year>>4)*10,2,16,BLACK);	//23
		OLED_ShowChinese(40,0,7,16,BLACK); //年
		
		OLED_ShowNum(60,0,(RTC_DateStruct.Month & 0x0f)+(RTC_DateStruct.Month>>4)*10,2,16,BLACK);	//7
		OLED_ShowChinese(79,0,8,16,BLACK); //月
		
		OLED_ShowNum(100,0,(RTC_DateStruct.Day & 0x0f)+(RTC_DateStruct.Day>>4)*10,2,16,BLACK);	//18
		OLED_ShowChinese(118,0,0,16,BLACK); //日
		
		OLED_ShowChinese(138,0,9,16,BLACK); //星
		OLED_ShowChinese(155,0,10,16,BLACK); //期
		OLED_ShowChinese(175,0,RTC_DateStruct.Week,16,BLACK); //五
		
		hour=(RTC_TimeStruct.Hour & 0x0f)+(RTC_TimeStruct.Hour>>4)*10;
		OLED_ShowNum(0,28,hour,2,64,BLACK); //时
		
		OLED_ShowNum(76,28,(RTC_TimeStruct.Minute & 0x0f)+(RTC_TimeStruct.Minute>>4)*10,2,64,BLACK); //分
		OLED_DrawRectangle(70,48,73,54,BLACK,1);	//：
}
void Update_Code(char* Code,u8 day_night);
void Show_Data()
{
		OLED_GUIInit();
		Paint_NewImage(Image_BW,OLED_W,OLED_H,0,WHITE);
		OLED_Clear(WHITE);

		Power_ON();
		OLED_GUIInit();

		Update_Time();	//更新时间
		Update_TH();	//更新湿度
	
		OLED_DrawRectangle(70,68,73,74,BLACK,1);	//框架线
		OLED_DrawLine(1,20,250,20,BLACK); //横线
		OLED_DrawLine(1,100,250,100,BLACK);
		OLED_DrawLine(150,60,205,60,BLACK);
		OLED_DrawLine(150,20,150,125,BLACK);	//竖线
		OLED_DrawLine(205,20,205,100,BLACK);
	
		//ADC使能
    ADC_Enable();
		REGBITS_SET(CW_ADC->START, ADC_START_START_Msk);//转换软启动
	  while (!ADC_ISR_EOC_Msk);
		u16 valueAdc = ADC_GetConversionValue();
		ADC_Disable();
		u8 block=((3.0/4096.0)*valueAdc-1.35)/0.02105-0.5; //图形块
		if(block>18) block=18;
		u8 percent=((3.0/4096.0)*valueAdc-1.35)/0.004; //百分比
		if(percent>100) percent=100;
		OLED_ShowPicture(227,2,24,12,Bat,WHITE); //电池电量图标
		OLED_DrawRectangle(249-block,4,249,14,BLACK,1); //231~249 0.4V分9份
		if(percent==100) OLED_ShowNum(202,2,100,3,12,BLACK); //电池电量数值
		else OLED_ShowNum(208,2,percent,2,12,BLACK); //电池电量数值
		OLED_ShowChar(220,2,'%',12,BLACK); //%
	
		//每个不曾起舞的日子，都是对生命的辜负
		
		//判定现在是白天还是晚上
		u8 day_or_night;
		if(6<=hour && hour<=18) day_or_night=1;//白天时间
		else day_or_night=0;
		//根据高分天气现象编码编排
		const u8* show_bmp;
		if(strcmp(code,"00")==0){	//晴
			if(day_or_night) show_bmp=icon_0d;
			else show_bmp=icon_0n;
		}
		else if(strcmp(code,"01")==0){//多云
			if(day_or_night) show_bmp=icon_1d;
			else show_bmp=icon_1n;
		}
		else if(strcmp(code,"02")==0){//阴天
			show_bmp=icon_2;
		}
		else if(strcmp(code,"03")==0){//阵雨
			if(day_or_night) show_bmp=icon_3d;
			else show_bmp=icon_3n;
		}
		else if(strcmp(code,"04")==0)//雷阵雨
			show_bmp=icon_4;
		else if(strcmp(code,"05")==0)//雷阵雨夹冰雹
			show_bmp=icon_5;
		else if(strcmp(code,"06")==0)//雨夹雪
			show_bmp=icon_6;
		else if(strcmp(code,"07")==0 || strcmp(code,"301")==0)//小雨 雨
			show_bmp=icon_7;
		else if(strcmp(code,"08")==0 || strcmp(code,"21")==0)//中雨 小雨-中雨
			show_bmp=icon_8;
		else if(strcmp(code,"09")==0 || strcmp(code,"22")==0)//大雨 中雨-大雨
			show_bmp=icon_9;
		else if(strcmp(code,"10")==0 || strcmp(code,"23")==0)//暴雨 大雨-暴雨
			show_bmp=icon_10;
		else if(strcmp(code,"11")==0 || strcmp(code,"12")==0 || strcmp(code,"24")==0 || strcmp(code,"25")==0)//大暴雨-特大暴雨
			show_bmp=icon_11;
		else if(strcmp(code,"13")==0)//阵雪
			show_bmp=icon_13;
		else if(strcmp(code,"14")==0 || strcmp(code,"302")==0)//小雪 雪
			show_bmp=icon_14;
		else if(strcmp(code,"15")==0 || strcmp(code,"26")==0)//中学 小雪-中雪
			show_bmp=icon_15;
		else if(strcmp(code,"16")==0 || strcmp(code,"27")==0)//大雪 中雪-大雪
			show_bmp=icon_16;
		else if(strcmp(code,"17")==0 || strcmp(code,"28")==0)//暴雪 大雪-暴雪
			show_bmp=icon_17;
		else if(strcmp(code,"18")==0)//雾
			show_bmp=icon_18;
		else if(strcmp(code,"19")==0)//冻雨
			show_bmp=icon_19;
		else if(strcmp(code,"20")==0 || strcmp(code,"31")==0)//沙尘暴 强沙尘暴
			show_bmp=icon_20;
		else if(strcmp(code,"29")==0)//浮尘
			show_bmp=icon_29;	
		else if(strcmp(code,"30")==0)//扬尘
			show_bmp=icon_30;
		else if(strcmp(code,"32")==0 || strcmp(code,"49")==0 || strcmp(code,"58")==0)//浓雾 强浓雾 特强浓雾
			show_bmp=icon_32;
		else if(strcmp(code,"33")==0)//龙卷风
			show_bmp=icon_33;
		else if(strcmp(code,"34")==0)//若高吹雪
			show_bmp=icon_34;
		else if(strcmp(code,"35")==0)//轻雾
			show_bmp=icon_35;
		else if(strcmp(code,"53")==0 || strcmp(code,"54")==0 || strcmp(code,"55")==0 || strcmp(code,"56")==0)//霾
			show_bmp=icon_53;
		else if(strcmp(code,"57")==0)//大雾
			show_bmp=icon_57;
		else show_bmp=icon_2; //阴天
		OLED_ShowPicture(210,24,40,40,show_bmp,WHITE); //天气图标40*40 200bytes
		
		//weather_today
		if(temp<0) OLED_ShowChar(206,75,'-',12,BLACK);		//-
		OLED_ShowNum(212,67,temp,2,24,BLACK); //温度 整数部分
		OLED_ShowNum(239,67,(int)(temp*10)%10,1,24,BLACK); //温度 小数部分
		OLED_DrawRectangle(238,86,240,88,BLACK,1);	//小数点
		OLED_DrawCircle(249,69,2,BLACK,0);		//°
		
		if(today.high<0) OLED_ShowChar(152,108,'-',12,BLACK);		//-
		OLED_ShowNum(158,100,today.high,2,24,BLACK); //today.high
		OLED_ShowChar(182,100,'C',24,BLACK);		//C
		OLED_DrawCircle(184,104,2,BLACK,0);		//°
		OLED_ShowChar(195,110,'~',24,BLACK);	//~
		if(today.low<0) OLED_ShowChar(209,108,'-',12,BLACK);		//-
		OLED_ShowNum(215,100,today.low,2,24,BLACK); //today.low
		OLED_ShowChar(239,100,'C',24,BLACK);		//C
		OLED_DrawCircle(241,104,2,BLACK,0);		//°
		
		//code_d code_n
		
		//ip拼音
		
		OLED_ShowString(5,22,(u8*)"ip:",12,BLACK);		//ip
		OLED_ShowString(23,22,(u8*)ip,12,BLACK);		//ip
		
		Update_Code(today.code_day,1);
		OLED_ShowChinese(67,104,40,16,BLACK); //转
		Update_Code(today.code_night,0);
		

		OLED_Display(Image_BW);
		Power_OFF();
}

void Update_Code(char* Code,u8 day_night)
{
		//判断是day night
		u8 x3_1,x3_2,x3_3,x4_1,x4_2,x4_3,x4_4;
		if(day_night){ //day
			x3_1=14;x3_2=30;x3_3=46;
			x4_1=5;x4_2=21;x4_3=37;x4_4=53;
		}
		else { //night
			x3_1=89;x3_2=105;x3_3=121;
			x4_1=80;x4_2=96;x4_3=112;x4_4=128;
		}
		//当天天气白天
		if(strcmp(Code,"00")==0){
			OLED_ShowChinese(x3_2,104,11,16,BLACK); //晴
		}
		else if(strcmp(Code,"01")==0){
			OLED_ShowChinese(x4_2,104,12,16,BLACK); //多
			OLED_ShowChinese(x4_3,104,13,16,BLACK); //云
		}
		else if(strcmp(Code,"02")==0){
			OLED_ShowChinese(x3_2,104,14,16,BLACK); //阴
		}
		else if(strcmp(Code,"03")==0){
			OLED_ShowChinese(x4_2,104,15,16,BLACK); //阵
			OLED_ShowChinese(x4_3,104,16,16,BLACK); //雨
		}
		else if(strcmp(Code,"04")==0){
			OLED_ShowChinese(x3_1,104,17,16,BLACK); //雷
			OLED_ShowChinese(x3_2,104,15,16,BLACK); //阵
			OLED_ShowChinese(x3_3,104,16,16,BLACK); //雨
		}
		else if(strcmp(Code,"05")==0){
			OLED_ShowChinese(x4_1,104,17,16,BLACK); //雷
			OLED_ShowChinese(x4_2,104,15,16,BLACK);//阵
			OLED_ShowChinese(x4_3,104,16,16,BLACK);//雨
			OLED_ShowChinese(x4_4,104,18,16,BLACK);//雹
		}
		else if(strcmp(Code,"06")==0){
			OLED_ShowChinese(x3_1,104,16,16,BLACK); //雨
			OLED_ShowChinese(x3_2,104,19,16,BLACK); //夹
			OLED_ShowChinese(x3_3,104,20,16,BLACK); //雪
		}
		else if(strcmp(Code,"07")==0 || strcmp(Code,"301")==0){
			OLED_ShowChinese(x4_2,104,21,16,BLACK); //小
			OLED_ShowChinese(x4_3,104,16,16,BLACK); //雨
		}
		else if(strcmp(Code,"08")==0 || strcmp(Code,"21")==0){//中雨 小雨-中雨
			OLED_ShowChinese(x4_2,104,22,16,BLACK); //中
			OLED_ShowChinese(x4_3,104,16,16,BLACK); //雨
		}
		else if(strcmp(Code,"09")==0 || strcmp(Code,"22")==0){//大雨 中雨-大雨
			OLED_ShowChinese(x4_2,104,23,16,BLACK); //大
			OLED_ShowChinese(x4_3,104,16,16,BLACK); //雨
		}
		else if(strcmp(Code,"10")==0 || strcmp(Code,"23")==0){//暴雨 大雨-暴雨
			OLED_ShowChinese(x4_2,104,24,16,BLACK); //暴
			OLED_ShowChinese(x4_3,104,16,16,BLACK); //雨
		}
		else if(strcmp(Code,"11")==0 || strcmp(Code,"12")==0 || strcmp(Code,"24")==0 || strcmp(Code,"25")==0){//大暴雨-特大暴雨
			OLED_ShowChinese(x3_1,104,23,16,BLACK); //大
			OLED_ShowChinese(x3_2,104,24,16,BLACK); //暴
			OLED_ShowChinese(x3_3,104,16,16,BLACK); //雨
		}
		else if(strcmp(Code,"13")==0){//阵雪
			OLED_ShowChinese(x4_2,104,15,16,BLACK); //阵
			OLED_ShowChinese(x4_3,104,20,16,BLACK); //雨
		}
		else if(strcmp(Code,"14")==0 || strcmp(Code,"302")==0){//小雪 雪
			OLED_ShowChinese(x4_2,104,21,16,BLACK); //小
			OLED_ShowChinese(x4_3,104,20,16,BLACK); //雪
		}
		else if(strcmp(Code,"15")==0 || strcmp(Code,"26")==0){//中学 小雪-中雪
			OLED_ShowChinese(x4_2,104,22,16,BLACK); //中
			OLED_ShowChinese(x4_3,104,20,16,BLACK); //雪
		}
		else if(strcmp(Code,"16")==0 || strcmp(Code,"27")==0){//大雪 中雪-大雪
			OLED_ShowChinese(x4_2,104,23,16,BLACK); //大
			OLED_ShowChinese(x4_3,104,20,16,BLACK); //雪
		}
		else if(strcmp(Code,"17")==0 || strcmp(Code,"28")==0){//暴雪 大雪-暴雪
			OLED_ShowChinese(x4_2,104,24,16,BLACK); //暴
			OLED_ShowChinese(x4_3,104,20,16,BLACK); //雪
		}
		else if(strcmp(Code,"18")==0)//雾
			OLED_ShowChinese(x3_2,104,25,16,BLACK); //雾
		else if(strcmp(Code,"19")==0){//冻雨
			OLED_ShowChinese(x4_2,104,26,16,BLACK); //阵
			OLED_ShowChinese(x4_3,104,20,16,BLACK); //雨
		}
		else if(strcmp(Code,"20")==0 || strcmp(Code,"31")==0){//沙尘暴 强沙尘暴
			OLED_ShowChinese(x3_1,104,27,16,BLACK); //沙
			OLED_ShowChinese(x3_2,104,28,16,BLACK); //尘
			OLED_ShowChinese(x3_3,104,24,16,BLACK); //暴
		}
		else if(strcmp(Code,"29")==0){//浮尘
			OLED_ShowChinese(x4_2,104,29,16,BLACK); //浮
			OLED_ShowChinese(x4_3,104,28,16,BLACK); //尘
		}
		else if(strcmp(Code,"30")==0){//扬尘
			OLED_ShowChinese(x4_2,104,30,16,BLACK); //扬
			OLED_ShowChinese(x4_3,104,28,16,BLACK); //尘
		}
		else if(strcmp(Code,"32")==0 || strcmp(Code,"49")==0 || strcmp(Code,"58")==0){//浓雾 强浓雾 特强浓雾
			OLED_ShowChinese(x4_2,104,31,16,BLACK); //浓
			OLED_ShowChinese(x4_3,104,25,16,BLACK); //雾
		}
		else if(strcmp(Code,"33")==0){//龙卷风
			OLED_ShowChinese(x3_1,104,32,16,BLACK); //龙
			OLED_ShowChinese(x3_2,104,33,16,BLACK); //卷
			OLED_ShowChinese(x3_3,104,34,16,BLACK); //风
		}
		else if(strcmp(Code,"34")==0){//弱高吹雪
			OLED_ShowChinese(x4_1,104,35,16,BLACK); //雷
			OLED_ShowChinese(x4_2,104,36,16,BLACK);//阵
			OLED_ShowChinese(x4_3,104,37,16,BLACK);//雨
			OLED_ShowChinese(x4_4,104,20,16,BLACK);//雹
		}
		else if(strcmp(Code,"35")==0){//轻雾
			OLED_ShowChinese(x4_2,104,38,16,BLACK); //轻
			OLED_ShowChinese(x4_3,104,25,16,BLACK); //雾
		}
		else if(strcmp(Code,"53")==0 || strcmp(Code,"54")==0 || strcmp(Code,"55")==0 || strcmp(Code,"56")==0)//霾
			OLED_ShowChinese(x3_2,104,39,16,BLACK); //雾
		else if(strcmp(Code,"57")==0){//大雾
			OLED_ShowChinese(x4_2,104,23,16,BLACK); //大·
			OLED_ShowChinese(x4_3,104,25,16,BLACK); //雾
		}
		else OLED_ShowChinese(x3_2,104,14,16,BLACK); //阴


}

void NVIC_Configuration(void)
{
    __disable_irq();
    NVIC_EnableIRQ(RTC_IRQn);	//开RTC中断
		NVIC_EnableIRQ(UART2_UART5_IRQn);	//开UART2中断
    __enable_irq();
}


#ifdef  USE_FULL_ASSERT
void assert_failed(uint8_t* file, uint32_t line)
{
	
}
#endif
